﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Inlycat.Log;

namespace Inlycat.Log
{

    /// <summary>
    /// Author:gouzhun
    /// </summary>
    public class PLog
    {
        public static bool Enable
        {
            get { return LogManager.Instance.IsEnable; }
        }


        public static void Log(string logmsg)
        {
            if (Enable)
            {
                LogManager.Instance.Log(logmsg);
            }
        }

        public static void LogError(string logmsgError)
        {
            if (Enable)
            {
                LogManager.Instance.Log(logmsgError, null, null, Loglevels.Error);
            }
        }

        //public static void LogStringFormat(string )



        #region  Extensions

        public static void LogGreen(string logmsg)
        {
            string msg = "<color=green>" + logmsg + "</color>";
            Log(msg);
        }

        public static void LogBlue(string logmsg)
        {
            string msg = "<color=blue>" + logmsg + "</color>";
            Log(msg);
        }

        public static void LogRed(string logmsg)
        {
            string msg = "<color=red>" + logmsg + "</color>";
            Log(msg);
        }


        public static void Log<T>(IEnumerable<T> list, string title) where T : class
        {
            if (Enable)
            {
                string msg = title;

                msg += "Log List:" + list.Count() + " " + typeof(T).Name;
                for (int i = 0; i < list.Count(); i++)
                {
                    var item = list.ElementAt(i);
                    msg += i.ToString() + ": " + item.ToString();
                }
                Log(msg);
            }
        }

        public static void Log(IEnumerable list)
        {
            if (Enable)
            {
                foreach (var item in list)
                {
                    var newList = item as IEnumerable;
                    if (newList != null)
                    {
                        Log(newList);
                    }
                    else
                    {
                        LogManager.Instance.Log(item.ToString());
                    }
                }
            }
        }


        #endregion

    }




}